package review;

/**
 * Description:
 *
 * @Author:
 * @Date: 2024/7/20 15:38
 */
public class MyInterrupt2 extends Thread{
    volatile boolean flag = false; // 线程执行的退出标记
    @Override
    public void run() {
        while(!flag){
            System.out.println("MyThread...run...");
            try {
                Thread.sleep(3000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        // 创建MyInterrupt1对象
        MyInterrupt2 t2 = new MyInterrupt2();
        t2.start();

        // 主线程休眠6秒
        Thread.sleep(6000L);

        t2.stop();

    }
}
